<?php
require_once (HOME . '/include/base/FrontendController.php');
/**
 * 文章显示控制器
 * @author silenus
 *
 */
class article extends FrontendController {
	/**
	 * spClass ( 'm_article' );
	 */
	private $mod_article;
	function __construct() {
		parent::__construct ();
		$this->article ();
	}
	function article() {
		
		$this->mod_article = spClass ( 'm_article' );
	}
	function index() {
		$this->_assign_range ();
		$this->_assign_recent ();
		
		if ($article_id = $this->spArgs ( 'aid' )) { // 检查是否存在aid
			$article_result = $this->mod_article->getArticleByID ( $article_id );
			if (! empty ( $article_result )) { // 检查aid是否有效,即是否取得了结果
				$this->assign ( 'article', $article_result );
				dump ( $article_result );
				$this->display ( 'article.content.layout.html' );
			} else {
				// TODO spUrl();
				$this->error ( '错误的文章ID' );
			}
		} else {
			// TODO spUrl()
			$this->error ( '请提交章aid' );
		}
	}
	
	/**
	 * This is For Right Block
	 */
	private function _assign_range() {
		//文章近期访问排名
		//TODO
		$range = $this->mod_article->findAll ('post_time > 1', 'visited DESC' );
		$this->assign('range', $range);
	}
	
	/**
	 * This is For Right Block
	 */
	private function _assign_recent() {
		$recent = $this->mod_article->findAll ( array (
				'1' => '1'),'post_time DESC');
		$this->assign('recent', $recent);
	}
}